package com.xuwang.controller;

import com.xuwang.pojo.Food;
import com.xuwang.service.impl.FoodServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 菜品上报表(Food)表控制层
 *
 * @author abaaba
 * @since 2021-09-15 20:31:39
 * @version 1.0
 */
@RestController
@RequestMapping("/food")
@Api(value = "菜品上报表(Food)管理",tags = "菜品上报表(Food)管理接口API")
@ApiResponses({
        @ApiResponse(code=400,message="请求参数不完整或者错误"),
        @ApiResponse(code=404,message="找不到页面"),
        @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get"),
        @ApiResponse(code=406,message="页面地址和接口名冲突"),
        @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串"),
        @ApiResponse(code=500,message="后台服务逻辑错误")
})
public class FoodController {
    /**
     * 服务对象
     */
    @Resource
    private FoodServiceImpl foodServiceImpl;

    /**
     * 通过实体作为筛选条件查询
     * @param foodName      菜品名称
     * @param foodWarranty  菜品保质期
     * @param markType      制作类型
     * @param foodKindName  菜系
     * @param action        状态（审核与否）
     * @param isDelete      是否删除
     * @param companyName   公司名字
     * @param address       公司地址
     * @return       查询结果
     */
    @RequestMapping(value = "/selectForPage", method = RequestMethod.GET)
    @ApiOperation(value = "列表查询分页接口",notes = "列表查询分页接口",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "foodName",value = "菜品名称",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "foodWarranty",value = "菜品保质期",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "markType",value = "制作类型（写死）String类型",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "foodKind",value = "菜系id",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "action",value = "审核状态（-1,0,1.也可能多个）",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "isDelete",value = "是否删除",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "companyName",value = "公司名称",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "address",value = "公司地址",paramType = "query",dataType = "String",required = false)
    })
    public Map<String, Object> selectForPage(@RequestParam(name = "index") int index, @RequestParam(name = "page") int page,String foodName, String foodWarranty, String markType, Integer foodKind, String action, String isDelete, String companyName, String address) {
        return this.foodServiceImpl.selectForPage(index,page,foodName,foodWarranty,markType,foodKind,action,isDelete,companyName,address);
    }
    
    /**
     * 生产的时候，查询所有食品
     * @return 返回食品id和食品名字
     */
    @RequestMapping(value = "/selectAllFood", method = RequestMethod.GET)
    @ApiOperation(value = "生产的时候，查询所有数据接口",notes = "生产的时候，查询所有数据接口",httpMethod = "GET")
    public Map<String, Object> selectAllFood() {
        return this.foodServiceImpl.selectAllFood();
    }
 /**
     * 生产的时候，查询所有食品
     * @return 返回食品id和食品名字
     */
    @RequestMapping(value = "/selectAllFoodKind", method = RequestMethod.GET)
    @ApiOperation(value = "查所有的菜品类型",notes = "所有的菜品类型",httpMethod = "GET")
    public Map<String, Object> selectAllFoodKind() {
        return this.foodServiceImpl.selectAllFoodKind();
    }

    /**
     * 通过主键删除单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequestMapping(value = "/updateIsDeleteById", method = RequestMethod.POST)
    @ApiOperation(value = "根据一个主键修改一条删除状态的接口",notes = "根据一个主键修改一条删除状态的接口",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "主键",paramType = "query",dataType = "String",required = true),
//            @ApiImplicitParam(name = "isDelete",value = "是否删除",paramType = "query",dataType = "int",required = true),
    })
    public Map<String, Object> updateIsDeleteById(@RequestParam("id") String id) {
        return this.foodServiceImpl.updateIsDeleteById(id,1);
    }

    /**
     * 通过主键删除单条数据
     *
     * @param id 主键
     * @param action 是否已删除
     * @return 单条数据
     */
    @RequestMapping(value = "/updateActionById", method = RequestMethod.POST)
    @ApiOperation(value = "根据一个主键修改一条审批状态的接口",notes = "根据一个主键修改一条审批状态的接口",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "主键",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "action",value = "审核状态",paramType = "query",dataType = "int",required = true),
    })
    public Map<String, Object> updateActionById(@RequestParam("id") String id,@RequestParam("action") Integer action) {
        return this.foodServiceImpl.updateActionById(id,action);
    }

    /**
     * 批量删除多条数据
     *
     * @param ids 批量主键
     * @return 单条数据
     */
    @RequestMapping(value = "/updateIsDeleteByIds", method = RequestMethod.POST)
    @ApiOperation(value = "删除多条的接口",notes = "删除多条的接口",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids",value = "主键",paramType = "query",dataType = "String",required = true),
    })
    public Map<String, Object> updateIsDeleteByIds(@RequestParam("ids") String ids) {
        return this.foodServiceImpl.updateIsDeleteByIds(ids);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @RequestMapping(value = "/selectById", method = RequestMethod.GET)
    @ApiOperation(value = "通过主键查询一个**的接口",notes = "通过主键查询一个**的接口",httpMethod = "GET")
    public Map<String, Object> selectById(Integer id) {
        return this.foodServiceImpl.selectById(id);
    }
    
    /**
     * 通过主键更新单条数据
     *
     * @param food 一个数据库对应的POJO数据对象
     * @return 单条数据
     */
    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    @ApiOperation(value = "通过主键更新一个**的接口",notes = "通过主键更新一个**的接口",httpMethod = "POST")
    public Map<String, Object> updateById(@RequestBody @ApiParam(name = "food",value = "pojo模型",required = true) Food food,@Autowired HttpServletRequest request) {
        return this.foodServiceImpl.updateById(food,request);
    }
    
    /**
     * 通过一个pojo对象新增单条数据
     *
     * @param food 一个数据库对应的POJO数据对象
     * @return 返回插入的主键id
     */
    @Transactional
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    @ApiOperation(value = "根据完整记录新增一个**的接口",notes = "根据完整记录新增一个**的接口",httpMethod = "POST")
    public Map<String, Object> insert(@RequestBody @ApiParam(name = "food",value = "pojo模型",required = true) Food food, @Autowired HttpServletRequest request) {
        return this.foodServiceImpl.insert(food,request);
    }

}